package cn.com.dycc.party_work.apply.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.party_work.apply.entity.Apply;
import cn.com.dycc.party_work.apply.entity.UserAndApply;
import cn.com.dycc.party_work.apply.param.ApplyParam;
import cn.com.dycc.party_work.apply.param.FindApplyParam;
import cn.com.dycc.party_work.apply.service.ApplyNotFoundException;
import cn.com.dycc.party_work.apply.service.ApplyService;
import cn.com.dycc.util.JsonObjectResult;

/**
 * 
 * Description: 申请入党控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年6月21日 上午8:54:05.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/apply")
public class ApplyController extends BaseController {
	
	@Resource
	private ApplyService applyService;

	@RequestMapping("/add.do")	
	@ResponseBody
	public JsonObjectResult addApply(ApplyParam apply,HttpServletRequest req){
		int n = applyService.addApply(apply, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteApply(String apply_id,HttpServletRequest req){
		int n = applyService.deleteApply(apply_id, req);
		return new JsonObjectResult(n);
	}
	
	/*@RequestMapping("/deleteall.do")
	@ResponseBody
	public JsonObjectResult deleteAllApply(String apply_ids[],HttpServletRequest req){
		int n = applyService.deleteAllApply(apply_ids, req);
		return new JsonObjectResult(n);
	}*/
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updateApply(ApplyParam apply,HttpServletRequest req){
		int n = applyService.updateApply(apply, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findApply(String apply_id,HttpServletRequest req){
		Apply apply = applyService.findApply(apply_id, req);
		return new JsonObjectResult(apply);
	}
	
	@RequestMapping("/findone.do")
	@ResponseBody
	public JsonObjectResult findApplyById(String apply_id,HttpServletRequest req){
		UserAndApply apply = applyService.findApplyById(apply_id, req);
		return new JsonObjectResult(apply);
	}
	
	@RequestMapping("/findall.do")
	@ResponseBody
	public JsonObjectResult findAllApply(FindApplyParam param,HttpServletRequest req){
		String count = applyService.findApplyCount(param, req);
		List<UserAndApply> list = applyService.findAllApply(param,req);
		return new JsonObjectResult(count,list);
	}
	
	@ExceptionHandler(ApplyNotFoundException.class)
	@ResponseBody
	public JsonObjectResult applyException(ApplyNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(44,e);
	}
}
